<template>
  <!-- 评分卡页面 -->
  <div class="creditcard">
    <div class="top_bar">
      <div class="left">
        <!-- 搜索框 -->
        <el-input
          v-model="input4"
          class="w-50 m-2"
          placeholder="请输入要查询的评分卡名称"
        >
          <template #prefix>
            <el-icon class="el-input__icon"><search /></el-icon>
          </template>
        </el-input>
        <!-- 下拉菜单 -->
        <el-dropdown>
          <el-button
            class="zhuangtai"
            type="primary"
            style="background-color: white; border-color: gray; color: gray"
          >
            状态<el-icon class="el-icon--right"><arrow-down /></el-icon>
          </el-button>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>全部</el-dropdown-item>
              <el-dropdown-item>启用</el-dropdown-item>
              <el-dropdown-item>禁用</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
        <el-button type="primary" class="zhuangtai btn" @click="chaxun(input4)"
          >查询</el-button
        >
        <el-button class="zhuangtai btn btn1" @click="chongzhi">重置</el-button>
      </div>
      <div class="right" @click="dialogFormVisible = true">
        <el-button class="zhuangtai btn btn1" @click="dialogFormVisible = true"
          ><el-icon><Plus /></el-icon>新增</el-button
        >
      </div>
      <!-- 新增弹窗 -->

      <el-dialog v-model="dialogFormVisible" title="新增评分卡">
        <el-form :model="form">
          <el-form-item label="评分卡名称" width="10%">
            <el-input v-model="form" autocomplete="off" />
          </el-form-item>
          <el-form-item label="是否禁用" width="10%">
            <el-input v-model="form1" autocomplete="off" />
          </el-form-item>
        </el-form>
        <template #footer>
          <span class="dialog-footer">
            <el-button @click="dialogFormVisible = false">返回</el-button>
            <el-button type="primary" @click="addbtn(form)"> 提交 </el-button>
          </span>
        </template>
      </el-dialog>
    </div>
    <!-- 表格 -->
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="caScorecardid" label="序号" width="180" />
      <el-table-column prop="caScorecardname" label="评分卡名称" width="180" />
      <el-table-column prop="caState" label="状态">
        <template #default="scope">
          {{ scope.row.caState != 0 ? "启用" : "禁用" }}
        </template>
      </el-table-column>
      <el-table-column prop="caScorecardsc" label="分值"> </el-table-column>
      <el-table-column prop="操作" label="操作">
        <template #default="scope">
          <!-- <el-button type="danger" @click="handleDelete(scope.row.adminid)">Delete</el-button> -->
          <div class="iconbtn">
            <el-popover placement="top-start" trigger="hover" content="编辑">
              <template #reference>
                <el-icon><Edit /></el-icon>
              </template>
            </el-popover>

            <el-popover placement="top-start" trigger="hover" content="查看">
              <template #reference>
                <el-icon @click="yanjingbool"><View /></el-icon>
              </template>
            </el-popover>

            <el-popover placement="top-start" trigger="hover" content="删除">
              <template #reference>
                <el-icon @click="deletebtn(scope.row.caScorecardid)"
                  ><Delete
                /></el-icon>
              </template>
            </el-popover>

            <el-popover placement="top-start" trigger="hover" content="状态">
              <template #reference>
                <el-switch v-model="value1" @change="booldata(scope.row)" />
              </template>
            </el-popover>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      v-model:current-page="currentPage4"
      v-model:page-size="pageSize4"
      :page-sizes="[10, 20, 30, 40]"
      :small="small"
      :disabled="disabled"
      :background="background"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script setup>
import { ElNotification } from "element-plus";
import "element-plus/es/components/notification/style/css";
import service from "@/apis";
import { onMounted, ref } from "vue";

var input4 = ref();
// 表格内容
var tableData = ref([]);

// 小眼睛按钮
var yanjingbool = ref(true);

// 编辑开关
var value1bool = ref(true);
// 开关事件
var booldata =(state)=>{
  // 编辑修改状态
  console.log(state);
  value1.value=state
      // console.log(value1.value);
  // var res =service.dyclink.bianji({state})
  // console.log(res);


}

var value1bool = (data) => {
  console.log(data);
  ElNotification.closeAll();
  ElNotification.success({ message: "修改成功！" });
  // console.log(value1.value);
  if (value1._value) {
    data.caState = 1;
  } else {
    data.caState = 2;
  }
};

onMounted(async () => {
  var res = await service.dyclink.chaxun({});
  if (res.data.data.length != 0) {
    tableData.value = res.data.data;
  }
});

// 首页查询按钮
var chaxun = async (input4) => {
  console.log(input4);
  tableData.value = "";
  var res = await service.dyclink.chaxun({ caScorecardname: input4 });
  // console.log(res.data.data);
  tableData.value = res.data.data;
};

// 重置
var chongzhi = async () => {
  input4.value = "";
  var res = await service.dyclink.chaxun();
  if (res.data.data.length != 0) {
    tableData.value = res.data.data;
  }
};

// 删除列表
var deletebtn = async (data) => {
  console.log(data);
  var res = await service.dyclink.deletelist({ id: data });
  console.log(res);
  // 重新渲染
  var res = await service.dyclink.chaxun();

  tableData.value = res.data.data;
};

// 开关默认为true
var value1 = ref(true);

// 新增弹出对话框
var dialogFormVisible = ref(false);
var form = ref("");

// 引用qs
// import qs from "qs";

// 点击新增按钮
var addbtn = async (form) => {
  var res = await service.dyclink.banner_add({ caScorecardname: form });
  console.log(res.data);

  dialogFormVisible.value = false;
  var res = await service.dyclink.chaxun();
  // console.log(res.data.data);
  tableData.value = res.data.data;

  // console.log(res);
};

var caozuo = ref("XXX");
//鼠标滑过表格触发
// var enter = (data) => {
//   for (var i = 0; i < tableData; i++) {
//     caozuo.value = "aaa";
//   }
//   console.log(tableData);
// };
// var leave = (row) => {
//   caozuo.value = "XXX";
// };
// 分页内容
var currentPage4 = ref(1);
var pageSize4 = ref(10);
</script>


<style scoped lang="scss">
/* 顶部功能样式 */
.top_bar {
  display: flex;
  justify-content: space-between;
}
.left {
  display: flex;
  width: 50%;
  height: 40px;
  justify-content: space-between;
}
.m-2 {
  width: 286px;
  height: 40px;
}
.zhuangtai {
  /* margin-left: -20px; */
  height: 100%;
}
.btn {
  width: 100px;
}
.btn1 {
  color: #4aa5fe;
  border-color: #4aa5fe;
}
/* 表格样式 */
.is-scrolling-none {
  margin-top: 30px;
}
.iconbtn {
  width: 200px;
  text-align: center;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 20px;
  line-height: 32px;
  cursor: pointer;
}
/* 分页样式 */
.el-pagination {
  margin-top: 20px;
  position: absolute;
  left: 50%;
  transform: translate(-33%, 50%);
}
.el-dialog {
  height: 600px;
}
</style>